{include file="common/header"/}
<!--自定义JS-->
<script src="__DEMO__/index_v2.js"></script>
</head>
<!--处理打印显示title和url 的问题-->

<body class="gray-bg">
<div class="wrapper">
    <div class="row">
        <div class="layui-row">
            <!--筛选条件-->
            <div class="layui-col-xs6">
                <form class="layui-form" action="">
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="interest" lay-filter="aihao">
                                <option value="0"  selected="">全部记录</option>
                                <option value="1">出库记录</option>
                                <option value="2">入库记录</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <input type="text" class="layui-input" id="search_date" placeholder="开始 到 结束">
                    </div>
                    <div class="layui-inline">
                        <a style="margin-left: 10px" href="#">高级搜索</a>
                    </div>
                </form>
            </div>
            <div class="layui-col-xs6 ">
              <div class="float_right">
                  <!--<button type="button" class="layui-btn layui-btn-primary">导入</button>-->
                  <!--<button type="button" class="layui-btn">导出</button>-->
                  <!--<button type="button" class="layui-btn layui-btn-normal show-add-html-htn">添加</button>-->
              </div>
            </div>
        </div>
        <table class="layui-hide" id="order_recode_table" lay-filter="order_recode_table"></table>

        <script type="text/html" id="barDemo">
            <!--<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="view">查看</a>-->
            <!--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
    </div>
</div>
<script>
    layui.use(['table', 'laydate','form'], function () {
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;
        var layer = layui.layer;

        laydate.render({
            elem: '#search_date'
            , type: 'datetime'
            , range: '到'
            , format: 'yyyy年M月d日'
        });
        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        //详见：https://www.layui.com/doc/modules/table.html#totalRow

        table.render({
            elem: '#order_recode_table'
            ,url: '{:url("/printer/Inventory/inventoryRecode")}'
//                ,toolbar: '#toolbarDemo'
            , title: '库存记录表'
            , defaultToolbar: false
            , totalRow: true
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', title: 'ID', width: 80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                , {field: 'order_id', title: '订单号', width: 200,fixed: 'left'}
                , {field: 'print_type', title: '打印机型号',fixed: 'left'}
                , {field: 'consumable_type', title: '耗材型号',width: 200,}
                , {field: 'price', title: '单价',width: 120,totalRow: true}
                , {field: 'buy_num', title: '数量',width: 80,totalRow: true}
                , {field: 'create_by_user_name', title: '下单人',width: 80,}
                , {field: 'unit_name', title: '客户单位',width: 250,}
                , {field: 'unit_name_customer', title: '联系人',width: 100,}
                , {field: 'customer_tel', title: '联系人电话',width: 120,}
                , {field: 'create_time', title: '出库时间',width: 165}
//                , {field: 'comment', title: '出库时间', width: 180,fixed: 'right'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo',width: 80}

            ]],
            id: 'order_recode_table_reload'
            , page: true
        });







        //操作js
        //点击添加按钮
        //监听行工具事件
        table.on('tool(order_recode_table)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    del(data.id);
                    layer.close(index);
                });
            }
        });

        //删除
        function del(id){
            $.ajax({
                url: '{:url("/printer/Recode/delInventoryRecode")}',
                type: 'get',
                data : {id:id},
                cache: false,
                async: true,
                beforeSend: function () {
                    var index = layer.load(1, {
                        shade: [0.1, '#fff'], time: 3 * 1000 //0.1透明度的白色背景
                    });
                },
                complete: function () {
                    layer.closeAll('loading');
                },
                success: function (res) {
                    if(res.code > 0){
                        layer.msg(res.msg);
                        table.reload('order_recode_table_reload', {
                            page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        }, 'data');
                        return false;
                    }else{
                        layer.msg(res.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert('网络失败，请联系管理员', {icon: 2});
                }
            });
        }
    });
</script>
{include file="common/footer"/}
</body>
</html>
